//创建界面的js
var optionNum = 2;

var userOptionNum = 1;

var $cOption;

var $cMsg;

function createInit() {
	var id = $('#id').val();
	
	$('#manager').val('广发证券资产管理（广东）有限公司');
	
	getContent("/company/findAll", {}, true, function(data) {
		if (data != null) {
			data.forEach(function(d){ 
				//登记机构
				if(d.type==2){
					$('#registId').append('<option value="'+d.id+'">'+d.name+'</option>');
				}
				//交易所
				if(d.type==3){
					$('#exchangeId').append('<option value="'+d.id+'">'+d.name+'</option>');
				}
				//评级机构
				if(d.type==4){
					$('#ratingId').append('<option value="'+d.id+'">'+d.name+'</option>');
				}
			});
		}
	});	
	
	if(id){
		getContent("/project/find", 'id=' + id, true, function(data) {
			if (data != null) {
				$('#name').val(data.name);
				$('#shortName').val(data.shortName);
				$('#manager').val(data.manager);
				$('#expiredate').val((new Date(data.expiredate.time)).Format("MM/dd/yyyy"));
				$('#begindate').val((new Date(data.begindate.time)).Format("MM/dd/yyyy"));
				$('#establishdate').val((new Date(data.establishdate.time)).Format("MM/dd/yyyy"));
				$('#noobjectiondate').val((new Date(data.noobjectiondate.time)).Format("MM/dd/yyyy"));
				$('#confirmdate').val((new Date(data.confirmdate.time)).Format("MM/dd/yyyy"));
				$('#issueprice').val(data.issueprice);
				$('#threshold').val(data.threshold);
				$('#additional').val(data.additional);
				$('#unit').val(data.unit);
				$('#noobjectionCode').val(data.noobjectionCode);
				$('#depositUrl').val(data.depositUrl);
				$('#depositId').val(data.depositId);
				$('#superviseId').val(data.superviseId);
				$('#registId').select2('val',data.registId);
				$('#exchangeId').select2('val',data.exchangeId);
				$('#ratingId').select2('val',data.ratingId);
			}
		});
	}
}

function saveProject() {

	var data = {};
	data.id = $('#id').val();
	data.name = $('#name').val();
	data.shortName = $('#shortName').val();
	data.manager = $('#manager').val();
	data.expiredate = $('#expiredate').val();
	data.begindate = $('#begindate').val();
	data.establishdate = $('#establishdate').val();
	data.noobjectiondate = $('#noobjectiondate').val();
	data.confirmdate = $('#confirmdate').val();
	data.issueprice = $('#issueprice').val();
	data.threshold = $('#threshold').val();
	data.additional = $('#additional').val();
	data.unit = $('#unit').val();
	data.depositId = $('#depositId').val();
	data.superviseId = $('#superviseId').val();
	data.registId = $('#registId').val();
	data.exchangeId = $('#exchangeId').val();
	data.ratingId = $('#ratingId').val();
	data.noobjectionCode = $('#noobjectionCode').val();
	data.depositUrl = $('#depositUrl').val();
	var jdata = JSON.stringify(data);
	postContent("/project/save", jdata, true, function(data) {
		if (data != null) {
			alert('保存成功!');
		}
	});
}